package week_01;

public class ArrayList {
    public class Node {
        int value;
        int pre;
        int next;
    }

    int size = 8;
    Node[] node = new Node[size + 1];

    public int head;
    public int tail;
    public int total;

    public ArrayList() {
        this.total = 2;
        this.head = 1;
        this.tail = 2;
        node[head] = new Node();
        node[tail] = new Node();
        node[head].next = tail;
        node[tail].pre = head;

    }

    public void insert(int p, int val) {
        total++;
        Node q = new Node();
        node[total] = q;
        q.value = val;
        q.next = node[p].next;
        node[node[p].next].pre = total;
        node[p].next = total;
        node[total].pre = p;
    }

    public void remove(int p) {
        node[node[p].next].pre = node[p].pre;
        node[node[p].pre].next = node[p].next;
    }

    public void clear() {
        head = tail = total = 0;
        node = new Node[size + 1];
    }

}
